fix: clear latestCtx on executionContextDestroyed to prevent stale context routing#3
Open
void0x14 wants to merge 4 commits into
Open
fix: clear latestCtx on executionContextDestroyed to prevent stale context routing#3void0x14 wants to merge 4 commits into
void0x14 wants to merge 4 commits into
Conversation
…ntext routing When a subframe's execution context is destroyed, latestCtx was not cleared. This caused Runtime.evaluate (without contextId) to keep routing to the destroyed context, producing persistent 'Failed to find execution context' errors that never recovered. Fix: - executionContextDestroyed: clear latestCtx if it matches the destroyed context - executionContextsCleared: clear latestCtx for the session (navigation case) - Add test assertion verifying latestCtx is cleared after context destruction
BinaryMessage (opcode 0x02) was always sent regardless of compression state. CDP wire format is JSON text — engine recvWsTextAlloc only handles TEXT (0x01) and CONTINUATION (0x00) frames, causing WsFrameError. - Send: TextMessage when compress=false, BinaryMessage when compress=true - SendBatch: same fix SOURCE: Chrome DevTools Protocol — wire format is JSON text frames SOURCE: RFC 6455 Section 5.2 — opcode 0x01 = text, 0x02 = binary
When a subframe's execution context is destroyed, latestCtx is cleared (fix VulpineOS#1). But Juggler requires executionContextId in Runtime.evaluate. Without a fallback, foxbridge sends undefined → Juggler rejects. Add mainCtx map that tracks the main frame's execution context per session. Unlike latestCtx, mainCtx is updated on every main frame context creation (surviving navigation) and only cleared on executionContextsCleared (full navigation reset). Fallback chain: latestCtx → mainCtx → empty (Juggler error) This ensures Runtime.evaluate always has a valid contextId. Also fix binary framing: Send() now uses TextMessage (opcode 0x01) for uncompressed CDP frames instead of always BinaryMessage (0x02). Fixes VulpineOS#1
Instead of hardcoding type="undefined" when Juggler omits the type
field, infer the actual type from the JSON value:
- String value → type="string"
- Boolean value → type="boolean"
- Number value → type="number"
This fixes "Runtime.evaluate expected string, got type=undefined"
errors in CDP clients that check the type field.
SOURCE: Chrome DevTools Protocol — Runtime.evaluate returns {result:{type,value}}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1
…ntext routing
When a subframe's execution context is destroyed, latestCtx was not cleared. This caused Runtime.evaluate (without contextId) to keep routing to the destroyed context, producing persistent 'Failed to find execution context' errors that never recovered.
Fix: